﻿@model IEnumerable<Marbale.BusinessObject.AppSetting>
@{
    ViewBag.Title = "Customer";
    Layout = null;
}

<div id="valuesContainer">
    <div class="tabContent">
        <table>
            @foreach (var item in Model)
            {
                String type = item.Type.ToString();
                <tr>
                    <th>
                        @item.Caption :
                    </th>
                    <td>

                        @switch (type)
                        {
                            case "dropdown":
                                @Html.DropDownListFor(m => item.Value, new SelectList(((System.Web.Mvc.MultiSelectList)(ViewBag.RequiredLevel)).Items, "Value", "Text", selectedValue: item.Value), new { @class = "form-control", @style = "width:160px", id = @item.Name, Name = "myInput", @onchange = "javascript:DoSomething(this.value,this.id);" })
                                break;
                            case "string":
                                <input type="text" value="@item.Value" id="@item.Name" class="strings" name="myInput"/><br />
                                break;
                            case "color":
                                <input type="text" value="@item.Value" id="@item.Name" class="strings" name="myInput"/><br />
                                break;
                            case "bool":
                                <input type="checkbox" value="@item.Value" class="checktrue strings" name="allcheck" id="@item.Name"/><br />
                                break;
                            case "file":
                                <input type="file" value="@item.Value" class="strings" name="fileUploader" id="@item.Name"/><br />
                                break;
                            case "int":
                                <input type="number" value="@item.Value" class="strings" name="myInput" id="@item.Name"/><br />
                                break;
                                <input type="text" value="@item.Value" id="@item.Name" class="strings" name="myInput"/>
                        }
                    </td>
                </tr>  
            }
        </table>

        <div class="actionItems">
            <button class="btn btn-primary btn-md" role="button" onclick="SaveEmail()">Save</button>
            <button class="btn btn-primary btn-md" role="button" onclick="location.href='/'">Close</button>
        </div>
    </div>

</div>

<script>
    var appSettings = [];
    var appSettings1 = [];
    $('input[Name=myInput]').change(function () {
        var d = {
            Name: this.id,
            Value: this.value,
            ScreenGroup: 'Email'
        };

        appSettings.push(d);
    });
    function DoSomething(value, id) {
        var d = {
            Name: id,
            Value: value,
            ScreenGroup: 'Customer'
        };

        appSettings.push(d);
    }
    function SaveEmail() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: '@Url.Action("UpdateAppSettings", "SiteSetup")',

                data: JSON.stringify({ appSettings: appSettings }),

                dataType: "json",

                beforeSend: function () { },

                success: function (data) {
                    appSettings = [];
                    //  location.reload();
                    alert("Data Saved");
                }
            });

        }
        $(document).ready(function () {
            $('input[name="allcheck"]').each(function (index) {
                if ($(this).val().toLowerCase() == "true")

                    ($(this).prop('checked', true));
            });
        });

</script>
